Fix GUI upgrade check to handle upgrade from x-betaFOO to x.
authorRobert Lipe <robertlipe@gpsbabel.org>
Sun, 14 Apr 2019 00:26:04 +0000 (19:26 -0500)
committerRobert Lipe <robertlipe@gpsbabel.org>
Sun, 14 Apr 2019 00:26:04 +0000 (19:26 -0500)
configure
gbversion.h
gui/upgrade.cc
gui/upgrade.h

index 4c865ec37272e7ac090c3218cc7f7343fc55b182..95e230beb5d53dcf2fd9a3fc7343ee705296d513 100755 (executable)
--- a/configure
+++ b/configure
@@ -2209,7 +2209,7 @@ DOCVERSION=1.6.0
 # Increase GBBUILD for a new release (why? Where is this ever used?)
 # A: it's used by win32/gpsbabel.rc.in which is used by the setup program,
 GBBUILD=29
-PACKAGE_RELEASE="-beta20200413"
+PACKAGE_RELEASE="-beta20190413"
 
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_RELEASE "$PACKAGE_RELEASE"
index df6233abdd98a17a0e1ce81568d492462b23023b..0754c8e65ee626fa93593380fd93987e062e8648 100644 (file)
@@ -4,5 +4,5 @@
  *
  * Isn't simplification via automation grand?
  */
-#define VERSION "1.6.0-beta20200413"
+#define VERSION "1.6.0-beta20190413"
 #define WEB_DOC_DIR "http://www.gpsbabel.org/htmldoc-1.6.0"
index 8ce6b777d3ed54520da9fdbc1e03d99b3355e713..77c0ba187e55bc9e8bb2050f8a7fdedfc2b84ce9 100644 (file)
 
 #include <cstdio>
 
-#include <QDebug>
-#include <QDesktopServices>
-#include <QDomDocument>
-#include <QLocale>
-#include <QMessageBox>
-#include <QNetworkAccessManager>
-#include <QNetworkReply>
-#include <QNetworkRequest>
-#include <QSysInfo>
-#include <QUrl>
-#include <QVariant>
-
-
-#if 0
+#include <QtCore/QDebug>
+#include <QtCore/QLocale>
+#include <QtCore/QSysInfo>
+#include <QtCore/QUrl>
+#include <QtCore/QVariant>
+#include <QtCore/QVersionNumber>
+#include <QtGui/QDesktopServices>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QtNetwork/QNetworkRequest>
+#include <QtWidgets/QMessageBox>
+#include <QtXml/QDomDocument>
+
+
+#if 1
 static const bool testing = true;
 #else
 static const bool testing = false;
@@ -169,6 +170,38 @@ UpgradeCheck::updateStatus UpgradeCheck::getStatus()
   return updateStatus_;
 }
 
+// GPSBabel version numbers throughout the code mostly predate QVersionNumber
+// and are stored as strings. They may be of the form "1.6.0-beta20200413" 
+// which, if sorted as a string, will be after "1.6.0" which is bad. Use
+// this function to sort that out. (See what I did there? Bwaaaahah!) 
+bool UpgradeCheck::suggestUpgrade(QString from, QString to) 
+{
+  int fromIndex = 0;
+  int toIndex = 0;
+  QVersionNumber fromVersion  = QVersionNumber::fromString(from, &fromIndex);
+  QVersionNumber toVersion  = QVersionNumber::fromString(to, &toIndex);
+
+  // We don't have to handle every possible range because the server won't
+  // have more than a version or two live at any time.
+  if (fromVersion < toVersion) {
+    return true;
+  }
+  // Just look for the presence of stuff (not even the contents) of the 
+  // string. Shorter string (no "-betaXXX" wins)
+  if (fromVersion == toVersion) {
+    if (from.length() - fromIndex > to.length() - toIndex) {
+      return true;
+    }
+  }
+  return false;
+}
+// Some day when we have Gunit or equiv, add unit tests for: 
+//suggestUpgrade(updateVersion, currentVersion_);
+//suggestUpgrade("1.6.0-beta20190413", "1.6.0");
+//suggestUpgrade("1.6.0", "1.6.0-beta20190413");
+//suggestUpgrade("1.6.0-beta20190413", "1.7.0");
+//suggestUpgrade("1.7.0", "1.6.0-beta20190413");
+
 void UpgradeCheck::httpRequestFinished(QNetworkReply* reply)
 {
 
@@ -272,7 +305,7 @@ void UpgradeCheck::httpRequestFinished(QNetworkReply* reply)
     upgradeText = upgrade.firstChildElement("overview").text();
 
     // String compare, not a numeric one.  Server will return "best first".
-    if ((updateVersion > currentVersion_) && updateCandidate) {
+    if (suggestUpgrade(updateVersion, currentVersion_) && updateCandidate) {
       babelData_.upgradeOffers_++;
       updateStatus_ = updateNeeded;
       response = tr("A new version of GPSBabel is available.<br />"
index a0e7b6fc9ec63b85139b6ebff6866de84a94b4e9..352043402449a87000d84eee0af12d5ff2fefb7d 100644 (file)
@@ -63,6 +63,7 @@ private:
   QString getOsName();
   QString getOsVersion();
   QString getCpuArchitecture();
+  bool suggestUpgrade(QString from, QString to);
 
 private slots:
   void httpRequestFinished(QNetworkReply* reply);